package com.ruoyi.sys.energ.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.sys.energ.entity.TbEnergWarning;
import com.ruoyi.sys.energ.service.ITbEnergWarningService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 

预警策略设置Controller
 * 
 * @author ruoyi
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/system/warning")
public class TbEnergWarningController extends BaseController
{
    @Autowired
    private ITbEnergWarningService tbEnergWarningService;

    /**
     * 查询

预警策略设置列表
     */
    @PreAuthorize("@ss.hasPermi('system:warning:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbEnergWarning tbEnergWarning)
    {
        startPage();
        List<TbEnergWarning> list = tbEnergWarningService.selectTbEnergWarningList(tbEnergWarning);
        return getDataTable(list);
    }

    /**
     * 导出预警策略设置列表
     */
    @PreAuthorize("@ss.hasPermi('system:warning:export')")
    @Log(title = "预警策略设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbEnergWarning tbEnergWarning)
    {
        List<TbEnergWarning> list = tbEnergWarningService.selectTbEnergWarningList(tbEnergWarning);
        ExcelUtil<TbEnergWarning> util = new ExcelUtil<TbEnergWarning>(TbEnergWarning.class);
        util.exportExcel(response, list, " 预警策略设置数据");
    }

    /**
     * 获取

预警策略设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:warning:query')")
    @GetMapping(value = "/{ewId}")
    public AjaxResult getInfo(@PathVariable("ewId") Long ewId)
    {
        return AjaxResult.success(tbEnergWarningService.selectTbEnergWarningByEwId(ewId));
    }

    /**
     * 新增

预警策略设置
     */
    @PreAuthorize("@ss.hasPermi('system:warning:add')")
    @Log(title = "预警策略设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbEnergWarning tbEnergWarning)
    {
        return toAjax(tbEnergWarningService.insertTbEnergWarning(tbEnergWarning));
    }

    /**
     * 修改预警策略设置
     */
    @PreAuthorize("@ss.hasPermi('system:warning:edit')")
    @Log(title = "预警策略设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbEnergWarning tbEnergWarning)
    {
        return toAjax(tbEnergWarningService.updateTbEnergWarning(tbEnergWarning));
    }

    /**
     * 删除预警策略设置
     */
    @PreAuthorize("@ss.hasPermi('system:warning:remove')")
    @Log(title = " 预警策略设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ewIds}")
    public AjaxResult remove(@PathVariable Long[] ewIds)
    {
        return toAjax(tbEnergWarningService.deleteTbEnergWarningByEwIds(ewIds));
    }
}
